package com.walker.util;

import java.util.HashMap;
import java.util.Map;

public class CompareLongUtil {
	public interface Operation {
        boolean calculate(long a, long b);
    }

    public static final Map<String, Operation> opMap = new HashMap<String, Operation>();
    static {
        opMap.put(">", ((a, b) -> a > b));
        opMap.put(">=", ((a, b) -> a >= b));
        opMap.put("<", ((a, b) -> a < b));
        opMap.put("<=", ((a, b) -> a <= b));
        opMap.put("==", ((a, b) -> a == b));
    }
    
    public static boolean compare(Object comparisonExpr,long resultValue,long referValue, long threshold) {
    	//绝对值
    	if (comparisonExpr.equals("||")) { 
    		resultValue = Math.abs(resultValue - referValue);
    		comparisonExpr = "<=";
    	}
    	//向上
    	if (comparisonExpr.equals("++")) {
    		resultValue = resultValue - referValue;
    		comparisonExpr = ">";
    	}
    	//向下
    	if (comparisonExpr.equals("--")) {
    		resultValue = -(resultValue - referValue);
    		comparisonExpr = ">";
    	}
    	boolean decide = CompareLongUtil.opMap.get(comparisonExpr).calculate(resultValue,threshold);
		return !decide;
    }
    
    public static void main(String[] args) {
    	 String str = ">=";
         int ab = 15;
         int ac = 10;
         int abs = ac-ab;
         System.out.println("abs:"+abs);
         boolean res = CompareLongUtil.opMap.get(str).calculate(ab,ac);
         System.out.println("ssssssss:" + res);
	}
}
